#include <stdio.h>
#include <sqlite3.h>

int main(int argc, char const *argv[])
{
    sqlite3* db = NULL;
    int ret = sqlite3_open("1.db",&db);
    if (ret != SQLITE_OK)
    {
        printf("sqlite3_open err\n");
        return 0;
    }

    printf("open success\n");

    char buf[256] = "select * from stu;";

    char* errmsg = NULL;
    char** resultp = NULL;
    int nrow=0;
    int ncolumn=0;
    ret = sqlite3_get_table(db,buf,&resultp,&nrow,&ncolumn,&errmsg);
    if (ret!=SQLITE_OK)
    {
        printf("err = %s\n",errmsg);
        sqlite3_free(errmsg);
        return -1;
    }

    char** p=NULL;
    p=resultp+ncolumn;

    for (int i = 0; i < nrow; i++)
    {
        for (int j = 0; j < ncolumn; j++)
        {
            printf("%s:%s\n",resultp[j],p[i*ncolumn+j]);
        }
        
    }
    
    

    sqlite3_close(db);

    printf("close success\n");
      
    return 0;
}
